<template>
  <div class="app-container">
    <el-form label-width="85px" inline  class="demo-form-inline">
            <el-form-item label="账号名称">
                <el-input v-model="queryParams.user" clearable placeholder="请输入账号名称"></el-input>
            </el-form-item>
            <el-form-item label="帐号类型">
                <el-select v-model="queryParams.region1" clearable placeholder="请选择账号类型">
                    <el-option label="全部" value="shanghai"></el-option>
                    <el-option label="区域一" value="shanghai"></el-option>
                    <el-option label="区域二" value="beijing"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="关联商户">
                   <remote-select
                        filterable
                        remote
                        :remote-method = "remoteMethod"
                        v-model="queryParams.region8"
                        :labelKey ="selectParams.department.selectName"
                        :valueKey ="selectParams.department.id"
                        :action = "selectParams.department.selectApi"
                        :actionQuery = "selectParams.department.actionQuery"
                        :changeQuery = "selectParams.department.changeQuery"
                        :option = "selectParams.department.options"
                        placeholder="请输入关联商户名称"
                        @change-data="choseDepartment"
                        @after-action = "getDepartmentList"
                        ></remote-select >
            </el-form-item>
            <el-form-item label="帐号状态">
                <el-select v-model="queryParams.region3" clearable placeholder="请选择账号状态">
                    <el-option label="全部" value="shanghai"></el-option>
                    <el-option label="区域一" value="shanghai"></el-option>
                    <el-option label="区域二" value="beijing"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="queryObj">查询</el-button>
                <el-button type="success" @click="newObj">新建</el-button>
            </el-form-item>
            <el-row>
                <el-form-item>
                    <el-button type="warning" @click ='fromObj'>帐号类型管理</el-button>
                </el-form-item>
            </el-row>
    </el-form>
    <page-table ref="table" index :fetch="getTableList" :query="queryParams">
      <el-table-column align="center" min-width="120" label="账号名称" prop="col1"  show-overflow-tooltip/>
      <el-table-column align="center" min-width="120" label="账号类型" prop="col2"  show-overflow-tooltip/>
      <el-table-column align="center" min-width="120" label="关联商户" prop="col3"  show-overflow-tooltip/>
      <el-table-column align="center" min-width="120" label="账号状态" prop="col4" show-overflow-tooltip/>
      <el-table-column align="center" min-width="120" label="最后编辑人" prop="col5" show-overflow-tooltip/>
      <el-table-column align="center" min-width="180" label="创建时间" prop="col5" show-overflow-tooltip/>
      <el-table-column align="center" min-width="200" label="操作" >
        <template slot-scope="{row}">
          <el-button type="text" @click="editObj(row)">编辑</el-button>
          <el-button type="text" @click="stopObj(row)">停用</el-button>
          <el-button type="text" style="color: #FF0000;" @click="deleteObj(row)">删除</el-button></template>
      </el-table-column>
    </page-table>
    <dialog-submit
           ref="submitDialog"
           :title="dialogTitle"
           :getParams = "getParams"
           :rules="rules"
            @dialogOk="submitOk"
            @dialogClose="submitClose"
           >
                <p v-if="!cardType" style="margin-left: 20px;">用户使用账号名称进行登录，密码默认为123456</p>
                <el-form-item label="账号名称" prop="arg1">
                    <el-input  v-model="params.arg1" clearable placeholder="请输入名称"></el-input>
                </el-form-item>
                <el-form-item  label="账号类型" prop="arg2">
                    <el-input  v-model="params.arg2" clearable placeholder="请输入去向"></el-input>
                </el-form-item>
                <el-form-item  label="关联商户" prop="arg5">
                  <remote-select
                        filterable
                        remote
                        multiple
                        :remote-method = "dialogMethod"
                        v-model="params.arg5"
                        :labelKey ="selectParams.Dialogdepartment.selectName"
                        :valueKey ="selectParams.Dialogdepartment.id"
                        :action = "selectParams.Dialogdepartment.selectApi"
                        :actionQuery = "selectParams.Dialogdepartment.actionQuery"
                        :changeQuery = "selectParams.Dialogdepartment.changeQuery"
                        :option = "selectParams.Dialogdepartment.options"
                        placeholder="请输入关联商户名称"
                        @change-data="choseDialogDepartment"
                        @after-action = "getDialogDepartmentList"
                        ></remote-select >
                </el-form-item>
                <el-form-item  label="账号状态">
                    <el-select  v-model="params.arg4" clearable placeholder="请选择市">
                        <el-option label="福州市" value="1"></el-option>
                        <el-option label="厦门市" value="2"></el-option>
                        <el-option label="三明市" value="3"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item  label="奖品核销码"  v-if="true" >
                  <el-input  v-model="params.name" :class="{inputDisable:true}" disabled ></el-input>
                </el-form-item>
               <el-form-item  label="  " >
                <el-button type="primary" v-if="cardType" @click="restObj">重置密码</el-button>
                </el-form-item>
       </dialog-submit>
  </div>
</template>

<script>
import { getExamplePageList } from '@/api/document'
import { getDepartmentList } from '@/api/staff'
export default {
  data () {
    return {
      queryParams: {},
      query: false,
      dialogTitle: '',
      params: {},
      rules: {
        arg1: { required: true, max: 8, message: '请输入名称,最多8个字', trigger: 'blur' },
        arg2: { required: true, message: '请输入客户去向', trigger: 'blur' },
        arg6: { required: true, message: '请输入联系方式', trigger: 'blur' }
      },
      selectParams: { // 选项接口参数
        department: {
          selectName: 'departmentName',
          id: 'id',
          selectApi: getDepartmentList,
          actionQuery: {
            type: 'option'
          },
          changeQuery: '',
          options: [],
          list: []
        },
        Dialogdepartment: {
          selectName: 'departmentName',
          id: 'id',
          selectApi: getDepartmentList,
          actionQuery: {
            type: 'option'
          },
          changeQuery: '',
          options: [],
          list: []
        }
      },
      cardType: false
    }
  },
  methods: {
    getTableList (query) {
      return getExamplePageList(query)
    },
    refreshTable () {
      this.$refs.table.refresh()
    },
    // 查询用
    getDepartmentList (msg) {
      this.selectParams.department.list = msg
    },
    choseDepartment (val, msg) {
      var remote = ''
      if (msg) {
        if (msg.departmentName !== undefined) {
          this.remoteMethod(msg.departmentName)
        } else {
          this.remoteMethod(remote)
        }
      } else {
        this.remoteMethod(remote)
      }
    },
    remoteMethod (query) {
      if (query !== '') {
        setTimeout(() => {
          this.selectParams.department.options = this.selectParams.department.list.filter((item, index) => {
            return item.departmentName.indexOf(query) > -1
          })
        }, 200)
      } else {
        this.selectParams.department.options = this.selectParams.department.list
      }
    },
    // 弹窗用
    getDialogDepartmentList (msg) {
      this.selectParams.Dialogdepartment.list = msg
    },
    choseDialogDepartment (val, msg) {
      var remote = ''
      if (msg) {
        if (msg.departmentName !== undefined) {
          this.dialogMethod(msg.departmentName)
        } else {
          this.dialogMethod(remote)
        }
      } else {
        this.dialogMethod(remote)
      }
    },
    dialogMethod (query) {
      if (query !== '') {
        setTimeout(() => {
          this.selectParams.Dialogdepartment.options = this.selectParams.Dialogdepartment.list.filter((item, index) => {
            return item.departmentName.indexOf(query) > -1
          })
        }, 200)
      } else {
        this.selectParams.Dialogdepartment.options = this.selectParams.Dialogdepartment.list
      }
    },
    fromObj () {
      this.$router.push({ path: 'AccountList_form' })
    },
    deleteObj (row) {
      var _this = this
      this.confirmBox({
        title: '确认删除账号',
        message: '账号' + '“' + row.col1 + '”' + '删除后，该账号将无法登陆，且不可恢复，确认删除后立即生效。',
        okText: '确认删除',
        callback (action, instance) {
          // 方法内使用js写法
          if (action === 'confirm') {
            _this.messageBox({
              message: '该账号已删除！'
            })
            _this.refreshTable()
          } else if (action === 'cancel') {
          }
        }
      })
    },
    getParams () {
      return this.params
    },
    newObj () {
      this.dialogTitle = '新建'
      this.$refs.submitDialog.dialogOpen()
      console.log(this.params)
    },
    editObj (row) {
      this.cardType = true
      this.dialogTitle = '编辑'
      var title = {
        id: 1
      }
      this.$refs.submitDialog.dialogOpen(title)
    },
    restObj () {
      var _this = this
      this.confirmBox({
        title: '确认重置密码',
        message: '密码重置后，该账号的密码将会初始化为123456。确认重置后立即生效，请慎重使用该功能！',
        okText: '确认重置',
        callback (action, instance) {
          // 方法内使用js写法
          if (action === 'confirm') {
            _this.messageBox({
              message: '重置成功！'
            })
            _this.refreshTable()
          } else if (action === 'cancel') {
          }
        }
      })
    },
    submitOk (params) {
      // 回调的是提交时候的完整参数
    },
    submitClose () {
      this.cardType = false
      this.params = {}
      this.$set(this.params, 'arg5', [])
    },
    stopObj (row) {
      var _this = this
      //    var title = ''
      //    var message = ''
      //    var backMessage = ''
      //    var activeStr = ''
      //    if (row.activeStr === '停用') {
      //      title = '确认停用账号'
      //      message = '账号' + row.col1 + '停用后，该账号将无法登陆，确认停用后立即生效。'
      //      backMessage = '该账号已停用！'
      //      activeStr = '停用'
      //    } else if (row.activeStr === '启用') {
      //      title = '确认启用账号'
      //      message = '账号' + row.col1 + '启用后，该账号将恢复使用，确认启动后立即生效。'
      //      backMessage = '该账号已启用！'
      //      activeStr = '启用'
      //    }
      this.confirmBox({
        title: '确认停用账号',
        message: '账号' + '“' + row.col1 + '”' + '停用后，该账号将无法登陆，确认停用后立即生效。',
        okText: '确认停用',
        callback (action, instance) {
          // 方法内使用js写法
          if (action === 'confirm') {
            _this.messageBox({
              message: '该账号已停用！'
            })
            _this.refreshTable()
          } else if (action === 'cancel') {
          }
        }
      })
    },
    queryObj () {
      this.query = this.queryed(this.queryParams)
      this.refreshTable()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
